#include "memory.h"

//#include "util.h"
#include "global.h"
#include "DBFileSystem.h"

DBFileSystem::DBFileSystem()
{
}

void
DBFileSystem::initDB()
{
	
}

list<Result>*
DBFileSystem::select (Table& table, char* indexValueBeg, char* indexValueEnd)
{
	return &(table.tmpDB);
}

void
DBFileSystem::insert
(Table& table, char* record, char* indexValueBeg, char* indexValueEnd)
{
	Result result;
	short len = *((short*)record);
	result.result = new char[len];
	memcpy(result.result, record, len);
	table.tmpDB.push_back(result);
}

list<Result>::iterator
DBFileSystem::del (Table& table, list<Result>::iterator iterResult
				   ,  char* indexValueBeg, char* indexValueEnd)
{
	return table.tmpDB.erase(iterResult);
}

void
DBFileSystem::update (Table& table, list<Result>::iterator iterResult
					  ,char* record , char* indexValueBeg, char* indexValueEnd)
{
	delete [] (iterResult->result);
	short len = *((short*)record);
	iterResult->result = new char[len];
	memcpy(iterResult->result, record, len);
}